package base.common;

import java.io.File;
import java.io.PrintWriter;
import java.nio.file.Paths;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
import java.util.Scanner;

import org.junit.Test;

public class JavaTest {
	@Test
	public void test() throws ParseException {
		DateFormat dt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();
		System.out.println(dt.format(date));
		System.out.println(date);
		System.out.println(dt.parse("2015-11-20 17:17:14"));

	}

	@Test
	public strictfp void test1() {
		int n = 0;
		int m = 0;
		System.out.println(n++);
		System.out.println(n);
		System.out.println(++m);
		System.out.println(m);
	}

	@Test
	public void test2() {
		String a = "dacd";
		String b = "babc";
		System.out.println(a.compareTo(b));
		System.out.println(a.charAt(1));
	}

	@Test
	public void test3() {
		// System.out.println(String.format("%1$tF %1$tT", new Date()));
		// System.out.println(String.format("%tF %<tT", new Date()));
		// System.out.printf("%12.2f",33.3333);
		// System.out.println(String.format("%s", new User()));
		String dir = System.getProperty("user.dir");
		System.out.println(System.getProperties());
	}

	/** thread.thread.test1Io */
	@Test
	public void test4() throws Exception {
		Scanner scanner = new Scanner(Paths.get("d:test.txt"));
		PrintWriter writer = new PrintWriter(new File("d:text.txt"));
		writer.print("book");
		writer.close();
	}

	@Test
	public void test5() throws Exception {
		System.out.println("ssssssssss");
		aa: for (int i = 0; i < 10; i++) {
			System.out.println(i);
			if (i == 5)
				break aa;
		}
	}

	@Test
	public void test6() throws Exception {
		// System.out.println(String.format("%tF %<tT",
		// System.currentTimeMillis()));

		// Pattern pattern=Pattern.compile("/\\d");
		// Matcher matcher= pattern.matcher("/9");
		// System.out.println(matcher.matches());

		System.out.println(Math.random());

		Calendar calendar = Calendar.getInstance();
		calendar.setFirstDayOfWeek(Calendar.SUNDAY);
		System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
		System.out.println(calendar.get(Calendar.DAY_OF_WEEK));
		System.out.println(calendar.getFirstDayOfWeek());
	}

	/** switch */
	@Test
	public void test7() throws Exception {
		String a = "";
		switch (a) {
		case "a":
			System.out.println("a");
			break;
		case "b":
			System.out.println("b");
			break;
		case "c":
			System.out.println("c");
			break;
		default:
			System.out.println("000");
			break;
		}
	}

	/** switch */
	@Test
	public void test8() throws Exception {
		Random rom1=new Random();
		//Random rom2=new Random();
		//System.out.println(rom1.nextInt(10));
		//System.out.println(rom2.nextInt());
		for(int i=0;i<1000;i++){
			int a=(int)(Math.random());
			System.out.println(Math.random());
		}
	}
	
	@Test
	public void testFile(){
				  
		new File("E:\\majian\\Workspaces\\MyEclipse10\\.metadata\\.me_tcat\\" +
				"webapps\\OneBox\\contentLibrary\\images\\office\\20160811103820467.PNG").delete();
	}
}
